import {createRouter, createWebHashHistory} from 'vue-router'

const router = createRouter({
    history: createWebHashHistory(import.meta.env.BASE_URL),  //使用hash模式服务器免配置
    routes: [
        {
            path: '/taskDetail',
            name: 'taskDetail',
            component: () => import('@/views/lookTask/taskDetail.vue'),  //路由懒加载
        },
        {
            path: '/openTask',
            name: 'openTask',
            component: () => import('@/views/lookTask/openTask.vue'),  //路由懒加载
        },
        {
            path: '/lookTask',
            name: 'lookTask',
            component: () => import('@/views/lookTask/index.vue'),  //路由懒加载
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/login.vue'),  //路由懒加载
        },
        {
            path: '/detail',
            name: 'detail',
            component: () => import('@/views/detail/index.vue'),  //路由懒加载
        },

        {
            path: '/',
            name: 'home',
            component: () => import('@/views/index.vue'),  //路由懒加载
            // children: [
            //     {
            //         path: 'videoSquare',
            //         component: () => import('@/views/videoSquare/index.vue'),  //路由懒加载
            //     },
            // ]

        },

        {
            path: '/task',
            name: 'task',
            component: () => import('@/views/task/index.vue'),  //路由懒加载
            // children: [
            //     {
            //         path: 'videoSquare',
            //         component: () => import('@/views/videoSquare/index.vue'),  //路由懒加载
            //     },
            // ]

        },
        {
            path: '/TaskDetailList',
            name: 'TaskDetailList',
            component: () => import('@/views/task/taskDetail.vue'),  //路由懒加载
            // children: [
            //     {
            //         path: 'videoSquare',
            //         component: () => import('@/views/videoSquare/index.vue'),  //路由懒加载
            //     },
            // ]

        }, {
            path: '/claimTask',
            name: 'ClaimTask',
            component: () => import('@/views/task/claimTask.vue'),  //路由懒加载
            // children: [
            //     {
            //         path: 'videoSquare',
            //         component: () => import('@/views/videoSquare/index.vue'),  //路由懒加载
            //     },
            // ]

        },

        // {
        //     path: '/test',
        //     name: 'about',
        //     component: () => import('../views/test.vue')
        // }
    ]
})
router.beforeEach((to, from, next) => {
    let userInfo = sessionStorage.getItem('userInfo')
    if (!userInfo) {
        if (to.fullPath != '/login') {
            router.push({path: '/login'})
        } else {
            next()
        }
    } else {
        next()
    }
});
export default router
